#!/bin/sh
# 先安装 conda 环境，使用默认版本，版本有问题再切换（执行 sh miniconda.sh）
service_name=material-flow.service
exe_path=/root/miniconda3/bin/python
service_path=/etc/systemd/system/$service_name
cwd=$(pwd)
pip install -r requirements.txt

if [ -f $service_path ]; then
    systemctl restart $service_name
    exit 0
fi

cat <<EOF > $service_path
[Unit]
Description=$service_name
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=$cwd
ExecStart=$exe_path $cwd/main.py
Restart=always
RestartSec=60

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable $service_name
systemctl start $service_name


